home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_12 / taylor / undrflow.cpp < prev   
C/C++ Source or Header  |  1995-08-17  |  1KB  |  52 lines

  1. // Fill input stream buffer
  2. int gpibin::underflow()
  3. {
  4.     int count,growth,inplimit;
  5.     char *temp;
  6.  
  7.     // See if we have allocated a stream buffer yet
  8.     if(base_ == NULL)
  9.     {
  10.        gleng_ = 128;      // a good starting length
  11.        base_ = new char[gleng_];
  12.        if(base_ == NULL)
  13.        {
  14.            cerr << "Can't allocate get stream buffer." << endl;
  15.            exit(1);
  16.        }
  17.        ebuf_ = base_ + gleng_;
  18.     }
  19.     inplimit = gleng_-1;
  20.     // Get entire gpib transfer
  21.     for(count=0;;)
  22.     {
  23.         ::ibrd(device,base_+count,inplimit);
  24.         status = ibsta;      // ibsta & ibcnt are NI globals
  25.         count += ibcnt;
  26.         if(status & (ERR|TIMO|END))  // Done if EOI or error
  27.            break;
  28.         growth = gleng_ >> 1;
  29.         temp = new char[gleng_ + growth];
  30.         if(temp == NULL)
  31.         {
  32.             cerr << "Can't increase get stream size." << endl;
  33.             exit(1);
  34.         }
  35.         // transfer to new area & release old area
  36.         memmove(temp,base_,gleng_);
  37.         delete base_;
  38.         base_ = temp;
  39.         inplimit = growth-1;
  40.         gleng_ += growth;
  41.     }
  42.     base_[count] = '\0';
  43.     if(base_[count-1] == '\n')
  44.       base_[--count] = '\0';
  45.     gptr_ = base_;
  46.     egptr_ = base_ + count;           // Set pointer to end of get portion
  47.  
  48.  
  49.     return *gptr_;
  50. }
  51.  
  52.